/**
*      author: Y_Yao
*      created: 2025-03-09 10:37:31
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int N = 10 + 7;
vector<vector<pair<int,int>>> a(N);
int n,m;
bool vis[N];
int ans = LLINF;
int start;

void dfs(int start,int target,int cur,int sum)
{
    if(cur == target)
    {
        ans = min(ans,sum);
        return;
    }
    for(auto& e : a[cur])
    {
        if(vis[e.first])continue;
        vis[e.first] = true;
        dfs(start,target,e.first,sum ^ e.second);
        vis[e.first] = false; 
    }
}

void solve()
{
    cin >> n >> m;
    for(int i = 1;i <= m;i++)
    {
        int u,v,w;
        cin >> u >> v >> w;
        a[u].push_back({v,w});
        a[v].push_back({u,w});
    }
    vis[1] = true;
    dfs(1,n,1,0);
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}